package com.vertxsample.samples.testweb.controller

import com.vertxsample.samples.core.web.BaseController
import com.vertxsample.samples.core.web.RequestContext
import com.vertxsample.samples.core.web.annotation.HttpAPI
import com.vertxsample.samples.core.web.annotation.HttpController
import com.vertxsample.samples.testweb.dao.SqlDAO
import io.vertx.core.http.HttpMethod
import io.vertx.core.json.Json
import java.util.concurrent.CompletableFuture
@HttpController(routerUri="/json")
class JsonController(requestContext: RequestContext) : BaseController(requestContext) {

    @HttpAPI(routerUri="/get/staff" ,returnType = "json",method = HttpMethod.GET)
    fun getStaff(): CompletableFuture<String> {
        val sqlDAO = SqlDAO(requestContext.dslContext);

        return sqlDAO.getStaff(requestContext.routingContext.queryParam("staffid")[0]).thenApply({result->Json.encode(result)})
    }
    @HttpAPI(routerUri="/get/unit" ,returnType = "json",method = HttpMethod.GET)
    fun getUnit(): CompletableFuture<String> {
        val sqlDAO = SqlDAO(requestContext.dslContext);

        return sqlDAO.getUnit(requestContext.routingContext.queryParam("unitid")[0]).thenApply({result->Json.encode(result)})
    }
}